home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GEN32.PAK / GENERIC.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  170 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   generic.c
  9. //
  10. //  PURPOSE:   Implement the windows procedure for the main application
  11. //    windows.  Also implement the generic message and command dispatchers.
  12. //
  13. //  FUNCTIONS:
  14. //    WndProc      - Processes messages for the main window.
  15. //    MsgCommand   - Handle the WM_COMMAND messages for the main window.
  16. //    MsgDestroy   - Handles the WM_DESTROY message by calling 
  17. //                   PostQuitMessage().
  18. //    CmdExit      - Handles the file exit command by calling destory 
  19. //                   window on the main window.
  20. //
  21. //  COMMENTS:
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. //#include <windowsx.h>
  26. #include "globals.h"            // prototypes specific to this application
  27.  
  28.  
  29. // Main window message table definition.
  30. MSD rgmsd[] =
  31. {
  32.     {WM_COMMAND, MsgCommand},
  33.     {WM_DESTROY, MsgDestroy}
  34. };
  35.  
  36. MSDI msdiMain =
  37. {
  38.     sizeof(rgmsd) / sizeof(MSD),
  39.     rgmsd,
  40.     edwpWindow
  41. };
  42.  
  43.  
  44. // Main window command table definition.
  45. CMD rgcmd[] =
  46. {
  47.     {IDM_EXIT,  CmdExit},
  48.     {IDM_ABOUT, CmdAbout}
  49. };
  50.  
  51. CMDI cmdiMain =
  52. {
  53.     sizeof(rgcmd) / sizeof(CMD),
  54.     rgcmd,
  55.     edwpWindow
  56. };
  57.  
  58.  
  59. //
  60. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  61. //
  62. //  PURPOSE:  Processes messages for the main window.
  63. //
  64. //  PARAMETERS:
  65. //    hwnd     - window handle
  66. //    uMessage - message number
  67. //    wparam   - additional information (dependant on message number)
  68. //    lparam   - additional information (dependant on message number)
  69. //
  70. //  RETURN VALUE:
  71. //    The return value depends on the message number.  If the message
  72. //    is implemented in the message dispatch table, the return value is
  73. //    the value returned by the message handling function.  Otherwise,
  74. //    the return value is the value returned by the default window procedure.
  75. //
  76. //  COMMENTS:
  77. //    Call the DispMessage() function with the main window's message dispatch
  78. //    information (msdiMain) and the message specific information.
  79. //
  80.  
  81. LRESULT CALLBACK WndProc(HWND   hwnd, 
  82.                          UINT   uMessage, 
  83.                          WPARAM wparam, 
  84.                          LPARAM lparam)
  85. {
  86.     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
  87. }
  88.  
  89.  
  90. //
  91. //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
  92. //
  93. //  PURPOSE: Handle the WM_COMMAND messages for the main window.
  94. //
  95. //  PARAMETERS:
  96. //    hwnd     - window handle
  97. //    uMessage - WM_COMMAND (Unused)
  98. //    GET_WM_COMMAND_ID(wparam, lparam)   - Command identifier
  99. //    GET_WM_COMMAND_HWND(wparam, lparam) - Control handle
  100. //
  101. //  RETURN VALUE:
  102. //    The return value depends on the message number.  If the message
  103. //    is implemented in the message dispatch table, the return value is
  104. //    the value returned by the message handling function.  Otherwise,
  105. //    the return value is the value returned by the default window procedure.
  106. //
  107. //  COMMENTS:
  108. //    Call the DispCommand() function with the main window's command dispatch
  109. //    information (cmdiMain) and the command specific information.
  110. //
  111.  
  112. #pragma argsused
  113. LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  114. {
  115.     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
  116. }
  117.  
  118.  
  119. //
  120. //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
  121. //
  122. //  PURPOSE: Calls PostQuitMessage().
  123. //
  124. //  PARAMETERS:
  125. //
  126. //    hwnd      - Window handle  (Unused)
  127. //    uMessage  - Message number (Unused)
  128. //    wparam    - Extra data     (Unused)
  129. //    lparam    - Extra data     (Unused)
  130. //
  131. //  RETURN VALUE:
  132. //
  133. //    Always returns 0 - Message handled
  134. //
  135. //  COMMENTS:
  136. //
  137. //
  138.  
  139. #pragma argsused
  140. LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  141. {
  142.      PostQuitMessage(0);
  143.      return 0;
  144. }
  145.  
  146. //
  147. //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
  148. //
  149. //  PURPOSE: Exit the application.
  150. //
  151. //  PARAMETERS:
  152. //    hwnd     - The window.
  153. //    wCommand - IDM_EXIT (unused)
  154. //    wNotify  - Notification number (unused)
  155. //    hwndCtrl - NULL (unused)
  156. //
  157. //  RETURN VALUE:
  158. //    Always returns 0 - command handled.
  159. //
  160. //  COMMENTS:
  161. //
  162. //
  163.  
  164. #pragma argsused
  165. LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  166. {
  167.      DestroyWindow(hwnd);
  168.     return 0;
  169. }
  170.